package com.ljyhhh.SmartCity.activity.server


import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.content.Intent
import android.graphics.BitmapFactory
import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import androidx.core.app.NotificationCompat
import com.ljyhhh.SmartCity.R
import com.ljyhhh.SmartCity.service.MyNotificationService

import kotlinx.android.synthetic.main.activity_my_server.*

class MyServer : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_my_server)
        val manager = getSystemService(Context.NOTIFICATION_SERVICE) as
                NotificationManager
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            val channel = NotificationChannel("normal", "Normal",NotificationManager.IMPORTANCE_DEFAULT)
            manager.createNotificationChannel(channel)

        }
        button_start_server.setOnClickListener {
            Toast.makeText(this,"server start ",Toast.LENGTH_SHORT).show()
            val intent= Intent(this, MyNotificationService::class.java)
            startService(intent)
        }

        button_stop_server.setOnClickListener {
            Toast.makeText(this,"server stop ", Toast.LENGTH_SHORT).show()
            val intent=Intent(this,MyNotificationService::class.java)
            stopService(intent)
        }
        tongzhi.setOnClickListener {
            val notification = NotificationCompat.Builder(this, "normal")
                .setChannelId("normal")
                .setContentTitle("This is content title")
                .setContentText("This is content text")
                .setSmallIcon(R.drawable.smail_icon)
                .build()
            manager.notify(1, notification)
        }
    }
}